package com.cjfather.redis.steam.annotation.consumers;

import java.nio.ByteBuffer;

import org.springframework.context.annotation.Scope;
import org.springframework.data.redis.connection.stream.ObjectRecord;
import org.springframework.stereotype.Component;

import com.cjfather.redis.steam.annotation.AnnoRedisStreamListener;
import com.cjfather.redis.steam.annotation.constants.RedisConstants;
import com.cjfather.redis.steam.controller.PropellingInfo;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author: todd
 * @date:   2023-08-08
 */

@Component
@Slf4j
@Scope("prototype")
@Data
public class TestPojoStreamConsumer extends RedisTemplateResource implements AnnoPojoConsumerI{
	/**
     * 消费组
     */
    private String group;
    /**
     * 消费组中的某个消费者
     */
    private String consumerName;
    
	private Gson gson = new GsonBuilder().create();


	@AnnoRedisStreamListener(streamKey = RedisConstants.NS_STREAM_KEY, consumerGroup = RedisConstants.NS_STREAM_KEY, consumerName = RedisConstants.NS_STREAM_KEY,consumerSize = 2)
	@Override
	public void onMessage(ObjectRecord<String, PropellingInfo> message) {
		int _1M = 1024 * 1024 * 1;
		ByteBuffer byteBuffer = ByteBuffer.allocateDirect(_1M);
		log.info("{}",message);
		log.info("key:{},组:{},消费者{} + stream message。messageId={}",RedisConstants.NS_STREAM_KEY, group,consumerName,message.getId());
	}

}
